country = 'indo'

v= 'any'
source(paste("config_code/",country,"_data_setup.R",sep = ""))
source(paste("config_code/",country,"_dependent_vars.R",sep = ""))
source(paste("config_code/",country,"_predictor_vars.R",sep = ""))

ds.labels <- attributes(dta)$var.labels

ds_snpk <- snpk_vars

ds_podes <- c("rhs_pds_stealL0",
              "rhs_pds_robberyL0",
              "rhs_pds_lootingL0",
              "rhs_pds_thuggeryL0",
              "rhs_pds_arsonL0",
              "rhs_pds_rapeL0",
              "rhs_pds_murderL0",
              "rhs_pds_fight_citL0",
              "rhs_pds_fight_secL0",
              "rhs_pds_fight_studL0",
              "rhs_pds_fight_tribeL0",
              "rhs_pds_vilconfindicatorL0",
              "rhs_pds_deathspercapL0",
              "rhs_pds_injpercapL0",
              "rhs_pds_num_sec_postL0",
              "rhs_pds_num_police_postL0",
              "rhs_pds_num_sec_officerL0",
              "rhs_pds_mudslide5",
              "rhs_pds_flood5",
              "rhs_pds_earthquake5",
              "rhs_pds_fire5",
              "rhs_pds_other",
              "rhs_pds_com_numhh_telL0",
              "rhs_pds_com_pubtv_dumL0",
              "rhs_pds_com_phnstall_dumL0",
              "rhs_pds_com_postal_dumL0",
              "rhs_pds_com_cell_strong_dumL0",
              "rhs_pds_com_cell_weak_dumL0",
              "rhs_pds_com_cell_tower_dumL0",
              "rhs_pds_com_numhh_radL0",
              "rhs_pds_com_numhh_dishL0",
              "rhs_pds_com_numhh_telL0",
              "rhs_pds_com_numhh_tvL0",
              "rhs_cns_telsignal_strengthL0",
              "rhs_pds_educ_KinderL0",
              "rhs_pds_educ_PriL0",
              "rhs_pds_educ_HighL0",
              "rhs_pds_educ_MadPedL0",
              "rhs_pds_educ_UniL0",
              "rhs_pds_populationL0",
              "rhs_pds_numvillagesL0",
              "rhs_pds_disttobupati",
              "rhs_pds_trans_bridge_dumL0",
              "rhs_pds_trans_busterm_dumL0",
              "rhs_pds_trans_seaport_dumL0",
              "rhs_pds_landarea",
              "rhs_pds_trans_plnlight_dumL0",
              "rhs_pds_trans_roadpass_dumL0",
              "rhs_pds_sht_hospL0",
              "rhs_pds_sht_mathospL0",
              "rhs_pds_sht_medpolyL0",
              "rhs_pds_sht_puskL0",
              "rhs_pds_sht_pustuL0",
              "rhs_pds_sht_DoctorL0",
              "rhs_pds_sht_MidWifeL0",
              "rhs_pds_sht_TradBirthL0",
              "rhs_pds_irrigated",
              "rhs_pds_market_perm",
              "rhs_pds_fac_SafeWater_dumL0",
              "rhs_pds_fac_Garbage_dumL0",
              "rhs_pds_fac_PubToilet_dumL0",
              "rhs_pds_fac_Cooking_dumL0",
              "rhs_pds_fac_hh_stelecL0",
              "rhs_pds_fac_hh_nstelecL0",
              "rhs_agc_majcash_wt",
              "rhs_agc_cash_wt",
              "rhs_agc_food_wt",
              "rhs_cns_rice_mill_small",
              "rhs_cns_rice_mill_large",
              "rhs_pds_any_pesantren",
              "rhs_cns_access_by4wheel_allyr",
              "rhs_gis_capdist",
              "rhs_cns_revenueTotal",
              "rhs_cns_revenueVillage",
              "rhs_cns_revenueTaxDesa",
              "rhs_cns_revenueSocialOrgs",
              "rhs_cns_revenueGotongRoyong",
              "rhs_cns_revenueOther",
              "rhs_cns_revenueGovt",
              "rhs_cns_revenueCentGovt",
              "rhs_cns_revenueProvGovt",
              "rhs_cns_revenueKabGovt",
              "rhs_cns_expendRoutine",
              "rhs_cns_expendDevelopment",
              "rhs_agc_majcash_wt",
              "rhs_agc_cash_wt",
              "rhs_agc_food_wt",
              "rhs_cns_any_farm_hold",
              "rhs_cns_shareHHabove0p1Ha",
              "rhs_cns_rice_primary",
              "rhs_pds_populationL0D3")
ds_dims <- c("rhs_dis_terrorismCountL0",
             "rhs_dis_terrorismDeathsL0",
             "rhs_dis_unrestCountL0",
             "rhs_dis_unrestDeathsL0",
             "rhs_dis_abrasionCountL0",
             "rhs_dis_abrasionDeathsL0",
             "rhs_dis_diseaseoutbreakCountL0",
             "rhs_dis_diseaseoutbreakDeathsL0",
             "rhs_dis_droughtCountL0",
             "rhs_dis_earthquakeCountL0",
             "rhs_dis_earthquakeDeathsL0",
             "rhs_dis_floodCountL0",
             "rhs_dis_floodDeathsL0",
             "rhs_dis_forestfireCountL0",
             "rhs_dis_indaccidentCountL0",
             "rhs_dis_indaccidentDeathsL0",
             "rhs_dis_landslideCountL0",
             "rhs_dis_landslideDeathsL0",
             "rhs_dis_tornadoCountL0",
             "rhs_dis_tornadoDeathsL0",
             "rhs_dis_transaccidCountL0",
             "rhs_dis_transaccidDeathsL0",
             "rhs_dis_tsunamiCountL0",
             "rhs_dis_tsunamiDeathsL0",
             "rhs_dis_volcanoCountL0",
             "rhs_dis_deathsL0",
             "rhs_dis_totdisastersL0"
)
ds_census <- c("rhs_cns_relF",
              "rhs_cns_relP",
              "rhs_cns_muslimShare",
              "rhs_cns_catholicShare",
              "rhs_cns_protestantShare",
              "rhs_cns_hinduShare",
              "rhs_cns_buddhistShare",
              "rhs_cns_confucianShare",
              "rhs_cns_shrchristian",
              "rhs_cns_ethF",
              "rhs_cns_ethP",
              "rhs_cns_ethS",
              "rhs_cns_shrchinese",
              "rhs_cns_shrarab",
              "rhs_cns_interEthnicMarriage",
              "rhs_cns_trading",
              "rhs_cns_selfemployed",
              "rhs_cns_agric",
              "rhs_cns_services",
              "rhs_cns_employer",
              "rhs_cns_shrag",
              "rhs_cns_shrforest",
              "rhs_cns_shrind",
              "rhs_cns_shrtrade",
              "rhs_cns_shrserv",
              "rhs_cns_shrtransport",
              "rhs_cns_schoolyr",
              "rhs_cns_shrnoschool",
              "rhs_cns_pop",
              "rhs_cns_numvillage",
              "rhs_cns_shrrural",
              "rhs_cns_mainroad_elec",
              "rhs_cns_access_by4wheel_allyr",
              "rhs_cns_male",
              "rhs_cns_married",
              "rhs_cns_childshare",
              "rhs_cns_youthshare",
              "rhs_cns_trading",
              "rhs_cns_selfemployed",
              "rhs_cns_agric",
              "rhs_cns_services",
              "rhs_cns_employer",
              "rhs_cns_shrag",
              "rhs_cns_shrforest",
              "rhs_cns_shrind",
              "rhs_cns_shrtrade",
              "rhs_cns_shrserv",
              "rhs_cns_shrtransport",
              "rhs_cns_relF",
              "rhs_cns_relP",
              "rhs_cns_muslimShare",
              "rhs_cns_catholicShare",
              "rhs_cns_protestantShare",
              "rhs_cns_hinduShare",
              "rhs_cns_buddhistShare",
              "rhs_cns_confucianShare",
              "rhs_cns_shrchristian",
              "rhs_cns_trading",
              "rhs_cns_selfemployed",
              "rhs_cns_agric",
              "rhs_cns_services",
              "rhs_cns_employer",
              "rhs_cns_shrag",
              "rhs_cns_shrforest",
              "rhs_cns_shrind",
              "rhs_cns_shrtrade",
              "rhs_cns_shrserv",
              "rhs_cns_shrtransport"
)

ds_susenas <- c("rhs_sns_hastelL0",
                "rhs_sns_hascelL0",
                "rhs_sns_hascomL0",
                "rhs_sns_accessedinternetL0",
                "rhs_sns_inschoolL0",
                "rhs_sns_literate_latinL0",
                "rhs_sns_ageL0",
                "rhs_sns_anyhealthprob0t5L0",
                "rhs_sns_bigthealth0t5L0",
                "rhs_sns_anyhealthprob6plusL0",
                "rhs_sns_bigthealth6plusL0",
                "rhs_sns_pcexp_medL0",
                "rhs_sns_pcexp_meanL0",
                "rhs_sns_giniL0",
                "rhs_sns_p0L0",
                "rhs_sns_p1L0",
                "rhs_sns_p2L0",
                "rhs_sns_av_pc_m_food_expL0",
                "rhs_sns_av_pc_m_nonfood_expL0",
                "rhs_sns_av_pc_m_hh_expL0",
                "rhs_sns_med_pc_m_food_expL0",
                "rhs_sns_med_pc_m_nonfood_expL0",
                "rhs_sns_med_pc_m_expL0",
                "rhs_sns_ineq9010L0",
                "rhs_sns_ineq8020L0",
                "rhs_sns_workedL0",
                "rhs_sns_unempL0",
                "rhs_sns_raskinriceL0",
                "rhs_cns_unemploy_rate")

ds_hwsd <- c("rhs_geo_AspectClN",
             "rhs_geo_AspectClE",
             "rhs_geo_AspectClS",
             "rhs_geo_AspectClU",
             "rhs_geo_AspectClW",
             "rhs_geo_Elev30as",
             "rhs_geo_for2000",
             "rhs_geo_grs2000",
             "rhs_geo_sq1",
             "rhs_geo_sq2",
             "rhs_geo_sq3",
             "rhs_geo_sq4",
             "rhs_geo_sq5",
             "rhs_geo_sq6",
             "rhs_geo_sq7",
             "rhs_geo_t_oc",
             "rhs_geo_t_ece",
             "rhs_geo_t_esp",
             "rhs_geo_t_ph_h2o",
             "rhs_geo_t_caso4",
             "rhs_geo_t_bs",
             "rhs_geo_texture1",
             "rhs_geo_texture2",
             "rhs_geo_texture3",
             "rhs_geo_drainage1",
             "rhs_geo_drainage2",
             "rhs_geo_drainage3",
             "rhs_geo_drainage4",
             "rhs_geo_drainage5",
             "rhs_geo_drainage6",
             "rhs_geo_rugged3",
             "rhs_geo_rugged5",
             "rhs_geo_rugged9",
             "rhs_geo_SlopesCl1",
             "rhs_geo_SlopesCl2",
             "rhs_geo_SlopesCl3",
             "rhs_geo_SlopesCl4",
             "rhs_geo_SlopesCl5",
             "rhs_geo_SlopesCl6",
             "rhs_geo_SlopesCl7",
             "rhs_geo_SlopesCl8"
)

ds_gec <- c("rhs_elec_mainstream1999local",
            "rhs_elec_extislamshare1999local",
            "rhs_elec_voteF1999local",
            "rhs_elec_voteP1999local",
            "rhs_elec_votetotal1999local",
            "rhs_elec_kabelectionyear",
            "rhs_elec_totvotesL0",
            "rhs_elec_mainstreamL0",
            "rhs_elec_extislamshareL0",
            "rhs_elec_voteFL0",
            "rhs_elec_votePL0",
            "rhs_elec_numpartiesL0"
)

ds_snl <- c( "rhs_mine_Bauxite_dist",
             "rhs_mine_Coal_dist",
             "rhs_mine_Copper_dist",
             "rhs_mine_Gold_dist",
             "rhs_mine_IronOre_dist",
             "rhs_mine_Nickel_dist",
             "rhs_mine_Tin_dist",
             "rhs_mine_Zinc_dist",
             "rhs_mine_Silver_dist"
)

ds_snlgem <- c( "rhs_shk_BauxiteShockL0",
                "rhs_shk_CoalShockL0",
                "rhs_shk_CopperShockL0",
                "rhs_shk_GoldShockL0",
                "rhs_shk_IronOreShockL0",
                "rhs_shk_NickelShockL0",
                "rhs_shk_TinShockL0",
                "rhs_shk_ZincShockL0",
                "rhs_shk_SilverShockL0"
)

ds_gem <- c("rhs_Bauxite_DlPL0",
            "rhs_Coal_DlPL0",
            "rhs_Copper_DlPL0",
            "rhs_Gold_DlPL0",
            "rhs_IronOre_DlPL0",
            "rhs_Nickel_DlPL0",
            "rhs_Tin_DlPL0",
            "rhs_Zinc_DlPL0",
            "rhs_Silver_DlPL0")

ds_dapoer <- c("rhs_dpr_totalrevpcL0",
               "rhs_dpr_ownrevpcL0",
               "rhs_dpr_totGDPpcL0",
               "rhs_dpr_agGDPpcL0"
)

ds_udel <- c("rhs_tmp_TempDevL0",
             "rhs_tmp_RainDevL0",
             "rhs_tmp_avRain",
             "rhs_tmp_avTemp",
             "rhs_tmp_sdRain",
             "rhs_tmp_sdTemp"
)

ds_podesfao <- c("rhs_shk_cash_wtDln_priceL0",
                 "rhs_shk_majcash_wtDln_priceL0",
                 "rhs_shk_food_wtDln_priceL0",
                 "rhs_shk_cash_wtDln_price_sd",
                 "rhs_shk_food_wtDln_price_sd",
                 "rhs_shk_majcash_wtDln_price_sd",
                 "rhs_agc_aggdpL0"
)

ds_fao <- c("rhs_avocado_DlPL0",
            "rhs_buffalolive_DlPL0",
            "rhs_cabbage_DlPL0",
            "rhs_carrot_DlPL0",
            "rhs_cashew_DlPL0",
            "rhs_cassava_DlPL0",
            "rhs_chickenlive_DlPL0",
            "rhs_chilipepper_DlPL0",
            "rhs_cocoa_DlPL0",
            "rhs_coffee_DlPL0",
            "rhs_cucumber_DlPL0",
            "rhs_eggplant_DlPL0",
            "rhs_greenbean_DlPL0",
            "rhs_groundnut_DlPL0",
            "rhs_maize_DlPL0",
            "rhs_mangoguavamangosteen_DlPL0",
            "rhs_oilpalmfruit_DlPL0",
            "rhs_orange_DlPL0",
            "rhs_papaya_DlPL0",
            "rhs_pepper_DlPL0",
            "rhs_potato_DlPL0",
            "rhs_rubber_DlPL0",
            "rhs_soybean_DlPL0",
            "rhs_sweetpotato_DlPL0",
            "rhs_tomato_DlPL0"
)

ds_henderson <- c("rhs_lightsL0")

dataset_key <- c()

for (x in ds_podes) {
  dataset_key[x] <-'Podes'
}
for (x in ds_snpk) {
  dataset_key[x] <-'SNPK'
}
for (x in ds_dims) {
  dataset_key[x] <-'DIMS'
}
for (x in ds_census) {
  dataset_key[x] <-'Census'
}
for (x in ds_susenas) {
  dataset_key[x] <-'Susenas'
}
for (x in ds_hwsd) {
  dataset_key[x] <-'HWSD'
}
for (x in ds_gec) {
  dataset_key[x] <-'GEC'
}
for (x in ds_snl) {
  dataset_key[x] <-'SNL'
}
for (x in ds_snlgec) {
  dataset_key[x] <-'SNL/GEM'
}
for (x in ds_gem) {
  dataset_key[x] <-'GEM'
}
for (x in ds_dapoer) {
  dataset_key[x] <-'DAPOER'
}
for (x in ds_udel) {
  dataset_key[x] <-'UDel'
}
for (x in ds_podesfao) {
  dataset_key[x] <-'Podes Ag Module/FAO'
}
for (x in ds_fao) {
  dataset_key[x] <-'FAO'
}
for (x in ds_henderson) {
  dataset_key[x] <-'Henderson et al. (2012)'
}

for (c in names(summary_categories)) {
  make_summary_table(filename = paste0('tables/',
                                       country,
                                       '_',
                                       c,
                                       '_summary.tex'),
                     ds=dta, 
                     xlist = summary_categories[[c]], 
                     label.list=ds.labels, 
                     dataset_key=dataset_key, 
                     group="adm_id_dec00", 
                     outcome=dv)
  
}
